package com.daro.ddlaunch.utils;

import com.alibaba.fastjson.JSONObject;
import com.daro.ddlaunch.dao.LaunchlogMapper;
import com.daro.ddlaunch.pojo.LaunchLog;
import com.daro.ddlaunch.pojo.Parameter;
import com.daro.ddlaunch.pojo.Position;
import org.springframework.beans.factory.annotation.Autowired;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class Utils {

/*    public static int getProbability() {

        return (int) ((Math.random()) * 100) < 70 ? 1 : 0;
    }*/

/*    public static List<Parameter> getParameter() {
        List<Parameter> list = new ArrayList<Parameter>();
        DecimalFormat df = new DecimalFormat("#.00");
        List<Position> position = getPosition();

        double speed = 0;
        double temperature = 38.6;

        for (Position position1 : position) {
            Parameter parameter = new Parameter();
            int time = position1.getTime();
            double longitude = position1.getLongitude();
            double latitude = position1.getLatitude();
            double height = position1.getHeight();
            for (int i = 1; i <= 100; i++) {
                if (i <= 20) {
                    speed += 23.21;
                }
                if (i >= 70) {
                    speed += 12.46;
                }
                if (i <= 50) {
                    temperature -= 1.6;
                } else {
                    temperature += 1.6;
                }
            }
            parameter.setTime(time);
            parameter.setLongitude(longitude);
            parameter.setLatitude(latitude);
            parameter.setHeight(height);
            parameter.setSpeed(Double.valueOf(df.format(speed)));
            parameter.setTemperature(Double.valueOf(df.format(temperature)));
            list.add(parameter);
        }
        return list;
    }*/


/*    public static List<Position> getPosition() {
        List<Position> list = new ArrayList<Position>();
        DecimalFormat df = new DecimalFormat("#.00");
        double longitude = 116.36;
        double latitude = 39.92;
        double b1 = 139.75;
        double b2 = 35.68;

        double f1 = (b1 - longitude) / 100;
        double f2 = (latitude - b2) / 100;

        int height = 0;

        for (int time = 1; time <= 100; time++) {
            Position position = new Position();
            if (time <= 50) {
                height += 10000;
            } else {
                height -= 10000;
            }
            longitude += f1;
            latitude -= f2;
            position.setTime(time);
            position.setLongitude(Double.valueOf(df.format(longitude)));
            position.setLatitude(Double.valueOf(df.format(latitude)));
            position.setHeight(height);
            list.add(position);
        }
        return list;
    }*/

    public static JSONObject parameter2JsonObject(Parameter p) {
        JSONObject json = new JSONObject();
        json.put("time", p.getTime());
        json.put("height", p.getHeight());
        json.put("latitude", p.getLatitude());
        json.put("longitude", p.getLongitude());
        json.put("speed", p.getSpeed());
        json.put("temperature", p.getTemperature());
        return json;
    }

    public static List<Position> getPosition(Parameter parameter) {
        String uuid = UUID.randomUUID().toString().replaceAll("-", "");

        List<Position> list = new ArrayList<Position>();
        DecimalFormat df = new DecimalFormat("#.00");
        double longitude = 116.403366;
        double latitude = 39.924768;
        double b1 = parameter.getLongitude();
        double b2 = parameter.getLatitude();

        double f1 = (b1 - longitude) / 100;
        double f2 = (latitude - b2) / 100;

        int height = 0;

        for (int time = 1; time <= 100; time++) {
            Position position = new Position();
            if (time <= 50) {
                height += 10000;
            } else {
                height -= 10000;
            }
            longitude += f1;
            latitude -= f2;
            position.setTime(time);
            position.setLongitude(Double.valueOf(df.format(longitude)));
            position.setLatitude(Double.valueOf(df.format(latitude)));
            position.setHeight(height);
            list.add(position);
        }

        return list;
    }

}
